<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ErrorLevel</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>

<body>
<h1>ErrorLevel</h1>

<p>This is a built-in variable that is set to indicate the success or failure of some of the commands (not all commands change the value of ErrorLevel). A value of 0 usually indicates success, and any other value usually indicates failure. You can also set the value of ErrorLevel yourself.</p>
<p>Of special interest is that <a href="../commands/Run.htm">RunWait</a> sets ErrorLevel to be the exit code of the program it ran. Most programs yield an exit code of zero if they completed successfully.</p>
<p>Each <a href="Threads.htm">thread</a> retains its own value of ErrorLevel, meaning that if the <a href="Threads.htm">current thread</a> is interrupted by another, when the original thread is resumed it will still have its original value of ErrorLevel, not the ErrorLevel that may have been set by the interrupting thread.</p>
<p>Note: Since some commands set ErrorLevel to values higher than 1, it is best not check whether ErrorLevel is 1, but instead whether ErrorLevel is not zero.</p>
<h3>Example</h3>
<pre class="NoIndent">WinWait, MyWindow, , 1
if ErrorLevel   <em>; i.e. it's not blank or zero.</em>
    MsgBox, The window does not exist.
else
    MsgBox, The window exists.</pre>
</body>
</html>
